using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;

namespace Sec_scan漏洞扫描系统.Sec_System
{
    /// <summary>
    /// 主页数据统计类
    /// <para>POC总数</para>
    /// <para>漏洞总数</para>
    /// <para>项目总数</para>
    /// <para>口令总数</para>
    /// <para>数据库支持</para>
    /// <para>敏感词</para>
    /// </summary>
    public class Sec_HomeData_Statistics
    {
        /// <summary>
        /// 漏洞总数统计
        /// </summary>
        /// <param name="poc"></param>
        /// <returns></returns>
        public static string PocStatistics(string poc)
        {
            string path = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_HomeData_Statistics_Api.D1);
            SQLiteConnection connection = new SQLiteConnection(path);
            try
            {
                connection.Open();
                if(connection.State == System.Data.ConnectionState.Open)
                {
                    //数据库能打开的情况下
                    string sql = Sec_Api.Sec_AllAPI.PocStatistics(Sec_Api.Sec_HomeData_Statistics_Api.D1);//查询漏洞数据库ID
                    SQLiteCommand command = new SQLiteCommand(sql, connection);
                    using(SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            //string pocs = dr["ID"].ToString();
                            int pocs = dr.GetInt32(dr.GetOrdinal("ID"));//使用这种方式进行统计
                            //int loop = Sec_Api.Sec_HomeData_Statistics_Api.Count++;
                            Sec_Api.Sec_HomeData_Statistics_Api.LoopTotal = pocs.ToString();
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                string exp = ex.ToString();
                Sec_Api.Sec_HomeData_Statistics_Api.ExpOptions = exp.ToString();
            }
            return poc;
        }
        /// <summary>
        /// 关键词统计
        /// </summary>
        /// <param name="poc"></param>
        /// <returns></returns>
        public static string WordStatistics(string poc)
        {
            string path = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_HomeData_Statistics_Api.D1);
            SQLiteConnection connection = new SQLiteConnection(path);
            try
            {
                connection.Open();
                if (connection.State == System.Data.ConnectionState.Open)
                {
                    //数据库能打开的情况下
                    string sql = Sec_Api.Sec_AllAPI.WordStatistics(Sec_Api.Sec_HomeData_Statistics_Api.D1);//查询漏洞数据库ID
                    SQLiteCommand command = new SQLiteCommand(sql, connection);
                    using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            //string pocs = dr["ID"].ToString();
                            int word = dr.GetInt32(dr.GetOrdinal("ID"));//使用这种方式进行统计
                            //int loop = Sec_Api.Sec_HomeData_Statistics_Api.Count++;
                            Sec_Api.Sec_HomeData_Statistics_Api.WordsTotal = word.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string exp = ex.ToString();
                Sec_Api.Sec_HomeData_Statistics_Api.ExpOptions = exp.ToString();
            }
            return poc;
        }
        /// <summary>
        /// 密码口令统计
        /// </summary>
        /// <param name="poc"></param>
        /// <returns></returns>
        public static string PassStatistics(string poc)
        {
            string path = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_HomeData_Statistics_Api.D1);
            SQLiteConnection connection = new SQLiteConnection(path);
            try
            {
                connection.Open();
                if (connection.State == System.Data.ConnectionState.Open)
                {
                    //数据库能打开的情况下
                    string sql = Sec_Api.Sec_AllAPI.PassStatistics(Sec_Api.Sec_HomeData_Statistics_Api.D1);//查询密码数据库ID
                    SQLiteCommand command = new SQLiteCommand(sql, connection);
                    using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            //string pocs = dr["ID"].ToString();
                            int pass = dr.GetInt32(dr.GetOrdinal("ID"));//使用这种方式进行统计
                            //int loop = Sec_Api.Sec_HomeData_Statistics_Api.Count++;
                            Sec_Api.Sec_HomeData_Statistics_Api.PassTotal = pass.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string exp = ex.ToString();
                Sec_Api.Sec_HomeData_Statistics_Api.ExpOptions = exp.ToString();
            }
            return poc;
        }
        /// <summary>
        /// 项目总数统计
        /// </summary>
        /// <param name="poc"></param>
        /// <returns></returns>
        public static string ProjectStatistics(string poc)
        {
            string path = Sec_Api.Sec_AllAPI.Sqlclient(Sec_Api.Sec_HomeData_Statistics_Api.D1);
            SQLiteConnection connection = new SQLiteConnection(path);
            try
            {
                connection.Open();
                if (connection.State == System.Data.ConnectionState.Open)
                {
                    //数据库能打开的情况下
                    string sql = Sec_Api.Sec_AllAPI.ProjectStatistics(Sec_Api.Sec_HomeData_Statistics_Api.D1);//查询项目数据库ID
                    SQLiteCommand command = new SQLiteCommand(sql, connection);
                    using (SQLiteDataReader dr = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                    {
                        while (dr.Read())
                        {
                            //string pocs = dr["ID"].ToString();
                            int pass = dr.GetInt32(dr.GetOrdinal("ID"));//使用这种方式进行统计
                            //int loop = Sec_Api.Sec_HomeData_Statistics_Api.Count++;
                            Sec_Api.Sec_HomeData_Statistics_Api.ProjectTotal = pass.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string exp = ex.ToString();
                Sec_Api.Sec_HomeData_Statistics_Api.ExpOptions = exp.ToString();
            }
            return poc;
        }
    }
}
